
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Jacob
 */
public class Main {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        final JFileChooser f = new JFileChooser();
        int r = f.showOpenDialog(null);
        if(r == JFileChooser.APPROVE_OPTION)
        {
            final PaintPanel p = new PaintPanel(f.getSelectedFile());
            JFrame fr = new JFrame("Glitcher");
            fr.add(p);
            fr.setVisible(true);
            fr.pack();
            p.updatePreview();
            fr.addWindowListener(new WindowListener()
            {

                @Override
                public void windowOpened(WindowEvent e) {

                }

                @Override
                public void windowClosing(WindowEvent e) {
                    Img2Bin.doConvert(p.image, f.getSelectedFile(), p.size);
                    System.exit(0);
                }

                @Override
                public void windowClosed(WindowEvent e) {

                }

                @Override
                public void windowIconified(WindowEvent e) {

                }

                @Override
                public void windowDeiconified(WindowEvent e) {

                }

                @Override
                public void windowActivated(WindowEvent e) {

                }

                @Override
                public void windowDeactivated(WindowEvent e) {

                }
            });
        }
        else
            return;
    }
}
